// 基于template/src/router/routes/view-route.ts.hbs生成
import qs from 'qs';
import AuthGuard from '../guard/auth-guard';
import { EntityRoute } from './entity-route';
import { userIndexRoute } from './user-route';

const viewRoute = [
	{
		path: '/index/:index?',
		name: 'index',
		meta: {
			caption: 'R7 Vue示例',
			tag: 'index',
			requireAuth: false,
			ignoreAddPage: false,
			startPage: true,
			parameters: [{ pathName: 'views', parameterName: 'index' }],
		},
		beforeEnter: (to: any, from: any, next: any) => {
			to.defaultPage = true;
			const routerParamsName = 'index';
			const params: any = {};
			if (to.params && to.params[routerParamsName]) {
				Object.assign(
					params,
					qs.parse(to.params[routerParamsName], { delimiter: ';' })
				);
			}
			const url: string = '/appdata';
			const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params);
			auth
				.then((result: any) => {
					next(result ? true : false);
				})
				.catch(() => {
					next(false);
				});
		},
		component: () => import('@views/sample/index/index.vue'),
		children: [
			{
				path: 'views/appindexview2',
				meta: {
					caption: '菜单右对齐',
					tag: 'AppIndexView2',
					requireAuth: false,
					ignoreAddPage: false,
					startPage: false,
					parameters: [{ pathName: 'views', parameterName: 'index' }],
				},
				component: () =>
					import('@views/sample/app-index-view-2/app-index-view-2.vue'),
			},
			{
				path: 'views/appportalview2',
				meta: {
					caption: '门户部件',
					tag: 'AppPortalView2',
					requireAuth: false,
					ignoreAddPage: false,
					startPage: false,
					parameters: [{ pathName: 'views', parameterName: 'index' }],
				},
				component: () =>
					import('@views/sample/app-portal-view-2/app-portal-view-2.vue'),
			},
			{
				path: 'views/appindexview',
				meta: {
					caption: '测试12231',
					tag: 'AppIndexView',
					requireAuth: false,
					ignoreAddPage: false,
					startPage: false,
					parameters: [{ pathName: 'views', parameterName: 'index' }],
				},
				component: () =>
					import('@views/ungroup/app-index-view/app-index-view.vue'),
			},
			{
				path: 'views/appportalview',
				meta: {
					caption: '工作台',
					tag: 'AppPortalView',
					requireAuth: false,
					ignoreAddPage: false,
					startPage: false,
					parameters: [{ pathName: 'views', parameterName: 'index' }],
				},
				component: () =>
					import('@views/ungroup/app-portal-view/app-portal-view.vue'),
			},
			{
				path: '/appredirectview',
				meta: {
					caption: '全局应用重定向视图',
					tag: 'AppRedirectView',
					requireAuth: false,
					ignoreAddPage: true,
					startPage: false,
					parameters: [
						{ pathName: 'appredirectview', parameterName: 'appredirectview' },
						{ pathName: 'views', parameterName: 'view' },
					],
				},
				//  component: () => import('@components/app-redirect-view/app-redirect-view.vue')
			},
			{
				path: 'apphtmlview/:apphtmlview?',
				meta: {
					caption: '应用HTML视图',
					tag: 'AppHtmlView',
					requireAuth: false,
					ignoreAddPage: false,
					startPage: false,
					parameters: [
						{ pathName: 'apphtmlview', parameterName: 'apphtmlview' },
						{ pathName: 'views', parameterName: 'view' },
					],
				},
				component: () =>
					import('@components/function/html-container/src/html-container.vue'),
			},
			...EntityRoute,
		],
	},
	{
		path: '/login/:login?',
		name: 'login',
		meta: {
			caption: '登录',
			tag: 'AppLoginView',
			requireAuth: false,
			ignoreAddPage: true,
			startPage: false,
		},
		component: () => import('@components/function/login/src/login.vue'),
	},
	{
		path: '/404',
		meta: {
			caption: '404',
			tag: 'AppNotFoundView',
			ignoreAddPage: true,
			requireAuth: false,
			startPage: false,
		},
		component: () => import('@components/function/404/src/404.vue'),
	},
	{
		path: '/500',
		meta: {
			caption: '500',
			tag: 'AppErrorView',
			ignoreAddPage: true,
			requireAuth: false,
			startPage: false,
		},
		component: () => import('@components/function/500/src/500.vue'),
	},
	{
		path: '/lock',
		meta: {
			caption: 'lock',
			tag: 'AppLockView',
			ignoreAddPage: true,
			requireAuth: false,
			startPage: false,
		},
		component: () => import('@components/function/lock/src/lock.vue'),
	},
	...userIndexRoute,
];

export const ViewRoute = viewRoute;
